package wjh.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import wjh.pojo.Doctor;
import wjh.pojo.ExamForm;
import wjh.pojo.Patient;
import wjh.pojo.ReportUserDoctor;
import wjh.service.ZlyDoctorService;
import wjh.service.ZlyExamFormService;
import wjh.service.ZlyPatientService;

@Controller
@RequestMapping("/doctor")
public class ZlyDoctorController {
    @Autowired
    private ZlyDoctorService zlyDoctorService;

    @Autowired
    private ZlyExamFormService zlyExamFormService;

    @Autowired
    private ZlyPatientService zlyPatientService;

    @RequestMapping("/docexam")
    public ModelAndView docExam() {
        int id = 1;
        Doctor doctor = zlyDoctorService.findById(id);
        //根据医生id查report_user_doctor表获取report_number、pid
        ReportUserDoctor reportUserDoctor = zlyExamFormService.findReportUserDoctorByDid(doctor.getId());
        if (reportUserDoctor != null){
            //根据pid查询到患者对象
            Patient patient = zlyPatientService.findById(reportUserDoctor.getUser_id());
            //根据report_number查询到报告单对象
            ExamForm examForm = zlyExamFormService.findByReportNumber(reportUserDoctor.getReport_Number());
            ModelAndView modelAndView = new ModelAndView("docExam");
            modelAndView.addObject("doctor", doctor);
            modelAndView.addObject("patient", patient);
            modelAndView.addObject("examForm", examForm);
            modelAndView.addObject("reportUserDoctor", reportUserDoctor);
            return modelAndView;
        }else {
            return new ModelAndView("docExamNone");
        }
    }
}
